<template>
  <div class="user-layout">
    <div class="user-container">
      <!-- 用户信息头部 -->
      <div class="user-header">
        <div class="user-info">
          <el-avatar :size="80" :src="userInfo?.avatar">
            <el-icon><User /></el-icon>
          </el-avatar>
          <div class="user-details">
            <h2 class="username">{{ userInfo?.username || '用户' }}</h2>
            <p class="user-email">{{ userInfo?.email || 'user@example.com' }}</p>
            <!-- 用户统计信息已移除 -->
          </div>
        </div>
      </div>

      <!-- 主要内容区 -->
      <div class="user-main">
        <!-- 左侧导航栏 -->
        <div class="user-sidebar">
          <el-menu
            :default-active="activeMenu"
            class="sidebar-menu"
            @select="handleMenuSelect"
          >
            <el-menu-item index="/user/profile">
              <el-icon><User /></el-icon>
              <span>个人中心</span>
            </el-menu-item>
            <el-menu-item index="/user/favorites">
              <el-icon><StarFilled /></el-icon>
              <span>我的收藏</span>
            </el-menu-item>
            <el-menu-item index="/user/settings">
              <el-icon><Setting /></el-icon>
              <span>账号设置</span>
            </el-menu-item>
            <el-menu-item index="/home">
              <el-icon><House /></el-icon>
              <span>返回首页</span>
            </el-menu-item>
          </el-menu>
        </div>

        <!-- 右侧内容区 -->
        <div class="user-content">
          <router-view />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ref, computed, watch } from 'vue'
import { useStore } from 'vuex'
import { useRouter, useRoute } from 'vue-router'
import { User, StarFilled, Setting, House } from '@element-plus/icons-vue'

export default {
  name: 'UserLayout',
  components: {
    User,
    StarFilled,
    Setting,
    House
  },
  setup() {
    const store = useStore()
    const router = useRouter()
    const route = useRoute()

    const activeMenu = ref('')

    // 计算属性
    const userInfo = computed(() => store.getters.getUserInfo)

    // 监听路由变化，更新激活菜单
    watch(
      () => route.path,
      (newPath) => {
        activeMenu.value = newPath
      },
      { immediate: true }
    )

    // 处理菜单选择
    const handleMenuSelect = (index) => {
      router.push(index)
    }

    // 用户统计数据加载已移除

    return {
      activeMenu,
      userInfo,
      handleMenuSelect
    }
  }
}
</script>

<style scoped>
.user-layout {
  min-height: calc(100vh - 64px);
  background: #f5f7fa;
  padding: 20px;
}

.user-container {
  max-width: 1200px;
  margin: 0 auto;
}

/* 用户信息头部 */
.user-header {
  background: white;
  border-radius: 12px;
  padding: 32px;
  margin-bottom: 20px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 24px;
}

.user-details {
  flex: 1;
}

.username {
  margin: 0 0 8px 0;
  font-size: 28px;
  font-weight: 600;
  color: #303133;
}

.user-email {
  margin: 0 0 16px 0;
  color: #909399;
  font-size: 16px;
}

/* 用户统计样式已移除 */

/* 主要内容区 */
.user-main {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

/* 左侧导航栏 */
.user-sidebar {
  width: 240px;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}

.sidebar-menu {
  border: none;
}

.sidebar-menu .el-menu-item {
  height: 56px;
  line-height: 56px;
  padding: 0 24px;
  margin: 0;
  border-radius: 0;
  transition: all 0.3s ease;
}

.sidebar-menu .el-menu-item:hover {
  background-color: rgba(64, 158, 255, 0.08);
  color: #409eff;
}

.sidebar-menu .el-menu-item.is-active {
  background-color: #409eff;
  color: white;
}

.sidebar-menu .el-menu-item.is-active .el-icon {
  color: white;
}

.sidebar-menu .el-menu-item .el-icon {
  margin-right: 12px;
  font-size: 18px;
}

/* 右侧内容区 */
.user-content {
  flex: 1;
  background: white;
  border-radius: 12px;
  min-height: 600px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .user-layout {
    padding: 10px;
  }
  
  .user-info {
    flex-direction: column;
    text-align: center;
    gap: 16px;
  }
  
  /* 移动端用户统计样式已移除 */
  
  .user-main {
    flex-direction: column;
  }
  
  .user-sidebar {
    width: 100%;
  }
  
  .sidebar-menu {
    display: flex;
    overflow-x: auto;
  }
  
  .sidebar-menu .el-menu-item {
    flex-shrink: 0;
    min-width: 120px;
    text-align: center;
  }
}
</style> 